<?php

class HelpController extends Controller {
	public function categoryAction() {
		Response::ajax(200, 'success', self::model('help_category')->getList());
	}

	public function listAction() {
		$categoryId = intval(Request::getParams('categoryId'));
		$type = intval(Request::getParams('type', 1));
		$page = intval(Request::getParams('page', 1));
		$pageSize = intval(Request::getParams('pageSize', 15));
		$order = 'sort asc, id desc';
		$where = $value = [];
		if ($type) {
			$where[] = 'type=?';
			$value[] = $type;
		} else {
			Response::ajax(NORMAL_ERROR, '参数错误,请求失败');
		}
		if ($categoryId) {
			$where[] = 'category_id=?';
			$value[] = $categoryId;
		} else {
			Response::ajax(NORMAL_ERROR, '参数错误,请求失败');
		}
		Response::ajax(200, 'success', self::model('help')->getList($where, $value, $order, $page, $pageSize));
	}

	public function infoAction() {
		$id = Request::getParams('id');
		if (!$id || !$info = self::model('help')->findById($id)) {
			Response::ajax(NORMAL_ERROR, '信息查看失败');
		}
		Response::ajax(200, 'success', $info);
	}
}